package com.example;

import com.example.enums.PeopleEnum;

import java.util.concurrent.CountDownLatch;

/**
 * @Author: wyp
 * @Date: 2021/9/9 17:33
 */
public class CountDownLatchDemo {
    static MakeFood makeFood = new MakeFood();
    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            System.out.println(PeopleEnum.getName(i).getName()+"餐准备制作...");
            new Thread(()->{
                makeFood.doMethod();
                countDownLatch.countDown();
            }, PeopleEnum.getName(i).getName()).start();
        }

        countDownLatch.await();
        System.out.println("全部餐制作完成，配送员正在配送！");
    }
}
class MakeFood{
    public void doMethod(){
        System.out.println(Thread.currentThread().getName()+"制作餐完成！");
    }
}
